import Vue from 'vue'
import Router from 'vue-router'

import Layout from '../layout/basicLayout.vue' //布局页


/**
 * 重写路由的push方法 
 *   防止  Navigating to current location ("/index") is not allowed
 * 		这种异常
 */
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}

Vue.use(Router)

/**
 * 基础路由 这里的配置不需要权限
 * @type { *[] }
 */

const constantRouterMap = [
  {
  		path: '/login',
  		component:resolve => require(['../view/user/login.vue'], resolve),
  		name: 'login'	
  },
  {
  		path: '/404',
  		component: resolve => require(['../view/exception/404.vue'], resolve)
  },
  {
      path: '',
      component: Layout, //应用布局页
      redirect: '/index',
      hidden: true
  },
  {
      path: '/index',
      component: Layout, //应用布局页
	  name:'index',
      meta:{
          title: "首页", //导航菜单项标题
          icon: 'el-icon-s-home' //导航菜单图标
      },
      children: [
        {
          path: '',
         component: resolve => require(['../view/base/index/Index.vue'], resolve),
          meta: {
            title: "主页",
            icon: 'el-icon-s-home',
            roles: ['admin','customer']
          }
        }
      ]
  }
]

// 动态路由 communication
export const asyncRoutes = [
  {
    path: '/base',
    component: Layout,
    meta: {
      title: "基本数据",
      icon: 'el-icon-s-marketing',
      hidden: false
    },
    children: [
      {
        path: 'customer',
        component: resolve => require(['../view/base/customer/Customer.vue'], resolve),
        meta: {
          title: "客户数据",
          icon: 'el-icon-tickets',
          hidden: false,
          roles: ['admin','customer']
        }
      },
	  {
	    path: 'oil',
	    component: resolve => require(['../view/base/oil/Oil.vue'], resolve),
	    meta: {
	      title: "油费",
	      icon: 'el-icon-tickets',
	      hidden: false,
	      roles: ['admin','customer']
	    }
	  },
	  {
	    path: 'transport',
	    component: resolve => require(['../view/base/transport/Transport.vue'], resolve),
	    meta: {
	      title: "运输费",
	      icon: 'el-icon-tickets',
	      hidden: false,
	      roles: ['admin','customer']
	    }
	  },
	  {
	    path: 'stone',
	    component: resolve => require(['../view/base/stone/Stone.vue'], resolve),
	    meta: {
	      title: "石子信息",
	      icon: 'el-icon-tickets',
	      hidden: false,
	      roles: ['admin','customer']
	    }
	  },
	  {
	    path: 'repair',
	    component: resolve => require(['../view/base/repair/Repair.vue'], resolve),
	    meta: {
	      title: "修理费",
	      icon: 'el-icon-tickets',
	      hidden: false,
	      roles: ['admin','customer']
	    }
	  },
	  {
	    path: 'tires',
	    component: resolve => require(['../view/base/tires/Tires.vue'], resolve),
	    meta: {
	      title: "轮胎费",
	      icon: 'el-icon-tickets',
	      hidden: false,
	      roles: ['admin','customer']
	    }
	  },
	  {
	    path: 'supple',
	    component: resolve => require(['../view/base/supple/Supple.vue'], resolve),
	    meta: {
	      title: "补充信息",
	      icon: 'el-icon-tickets',
	      hidden: false,
	      roles: ['admin','customer']
	    }
	  }
    ]
  },
  {
    path: '/rpt',
    component: Layout,
    meta: {
      title: "报表",
      icon: 'el-icon-s-marketing',
      hidden: false
    },
    children: [
      {
        path: 'payRPT',
        component: resolve => require(['../view/rpt/pay/payRPT.vue'], resolve),
        meta: {
          title: "应付报表",
          icon: 'el-icon-tickets',
          hidden: false,
          roles: ['admin','customer']
        }
      },
	  {
	    path: 'receiveRPT',
	    component: resolve => require(['../view/rpt/receive/receiveRPT.vue'], resolve),
	    meta: {
	      title: "应收报表",
	      icon: 'el-icon-tickets',
	      hidden: false,
	      roles: ['admin','customer']
	    }
	  },
	  {
	    path: 'monthlyBalanceRPT',
	    component: resolve => require(['../view/rpt/monthlyBalance/monthlyBalanceRPT.vue'], resolve),
	    meta: {
	      title: "月度余额报表",
	      icon: 'el-icon-tickets',
	      hidden: false,
	      roles: ['admin','customer']
	    }
	  }
	  ]
	}
]
export default new Router({
	routes: constantRouterMap.concat(asyncRoutes)
})
/*
export default new Router({
  routes:[
	//客户信息
	{
		path:"/base/customer",
		component: resolve => require(['../view/base/customer/Customer.vue'], resolve)
	},

	//用户登录页面
	{
	  
		path:"/user/login",
		component:resolve => require(['../view/user/login.vue'], resolve)
	}
  ]
})*/

